<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="商品名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入商品名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商品ID" prop="name">
        <el-input
          v-model="queryParams.id"
          placeholder="请输入商品ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="关键字" prop="keyword">
        <el-input
          v-model="queryParams.keyword"
          placeholder="请输入关键字"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="倍数" prop="keyword">
        <el-input
          v-model="queryParams.giftAmount"
          placeholder="请输入倍数"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="条形码" prop="barCode">
        <el-input
          v-model="queryParams.barCode"
          placeholder="请输入产品条形码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="品牌" prop="brand">
        <el-input
          v-model="queryParams.brand"
          placeholder="请输入品牌"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产地" prop="origin">
        <el-input
          v-model="queryParams.origin"
          placeholder="请输入产地"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="分类" prop="cateId">
        <el-select
          v-model="queryParams.cateId"
          placeholder="请选择分类"
          clearable
          size="small"
        >
          <el-option
            label="请选择字典生成"
            v-for="item in categoryOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="类型" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="请选择类型"
          clearable
          size="small"
        >
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="请选择状态"
          clearable
          size="small"
        >
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item style="display: block">
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['ds:product:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['ds:product:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['ds:product:remove']"
          >删除</el-button
        >
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['ds:product:export']"
        >导出</el-button>
      </el-col> -->
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="productList"
      @selection-change="handleSelectionChange"
      border
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="商品名" align="center" prop="name" width="200" />
      <!-- <el-table-column label="排序" align="center" prop="sort" /> -->
      <el-table-column label="商品图片" align="center" prop="image" width="150">
        <template slot-scope="scope">
          <img
            style="width: 80px; height: 80px; border: none"
            :src="scope.row.image"
          />
        </template>
      </el-table-column>
      <el-table-column label="分类ID" align="center" prop="cateId" />
      <el-table-column label="进价" align="center" prop="price" />
      <el-table-column label="售价" align="center" prop="vipPrice" />
      <el-table-column label="利润" align="center" prop="postage" />
      <el-table-column label="贡献值" align="center" prop="quota" />
      <el-table-column label="赠送倍数" align="center" prop="giftAmount" />
      <el-table-column label="销量" align="center" prop="sales" />
      <el-table-column label="库存" align="center" prop="stock" />
      <!--      <el-table-column label="状态" align="center" prop="status" />-->
      <!--      <el-table-column label="通证" align="center" prop="quota" >-->
      <!--        <template slot-scope="scope">-->
      <!--          <span>{{ scope.row.quota }}%</span>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <el-table-column
        label="添加时间"
        align="center"
        prop="createTime"
        class-name="small-padding fixed-width"
        width="150"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="上架/下架"
        align="center"
        class-name="small-padding fixed-width"
        width="100"
      >
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.status"
            inactive-color="#13ce66"
            active-color="#ff4949"
            :active-value="0"
            :inactive-value="1"
            @change="statusChecked($event, scope.row)"
          >
          </el-switch>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        fixed="right"
        class-name="small-padding fixed-width"
        width="200"
      >
        <template slot-scope="scope">
          <el-button
            type="primary"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['ds:product:edit']"
            >修改</el-button
          >
          <!-- <el-button
            type="danger"
            @click="handleDelete(scope.row)"
            v-hasPermi="['ds:product:remove']"
            >删除</el-button
          > -->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改商品信息对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="800px"
      append-to-bod
      :close-on-click-modal="false"
      @close="dialogClosed"
      ref="formDialog"
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="商品图片" prop="image">
          <imageUpload v-model="form.image" />
        </el-form-item>
        <el-form-item label="轮播图" prop="sliderImage">
          <el-upload
            :action="uploadImgUrl"
            :file-list="filesList"
            ref="upload"
            list-type="picture-card"
            :limit="3"
            @submit.native.prevent
            :headers="headers"
            :show-file-list="true"
            :on-change="fileChange"
            :on-remove="fileRemove"
            :on-success="handleUploadSuccess"
          >
            <i class="el-icon-plus"></i>
          </el-upload>
        </el-form-item>
        <el-form-item label="商品名" prop="name">
          <el-input v-model="form.name" placeholder="请输入商品名" />
        </el-form-item>
        <el-form-item label="商品简介">
          <editor v-model="form.info" :min-height="192" />
        </el-form-item>
        <el-form-item label="关键字" prop="keyword">
          <el-input v-model="form.keyword" placeholder="请输入关键字" />
        </el-form-item>
        <el-form-item label="分类ID" prop="cateId">
          <el-select
            v-model="form.cateId"
            placeholder="请选择分类"
            clearable
            size="small"
            style="width: 100%"
          >
            <el-option
              v-for="item in categoryList"
              :key="item.id"
              :label="item.cateName + '-' + item.id"
              :value="item.id"
            />
          </el-select>
        </el-form-item>

        <el-form-item
          v-if="form.cateId > 100 && form.cateId < 200"
          label="需要积分"
          prop="integral"
        >
          <el-input v-model="form.integral" placeholder="请输入需要积分" />
        </el-form-item>

        <el-form-item
          label="绿色积分"
          v-if="form.cateId == 275 || form.cateId == '275'"
          prop="greenPoints"
        >
          <el-input
            v-model.number="form.greenPoints"
            placeholder="请输入绿色积分"
          />
        </el-form-item>

        <el-form-item label="商家ID" prop="storeId">
          <el-input v-model="form.storeId" placeholder="请输入商家Id" />
        </el-form-item>

        <el-form-item label="进价" prop="price">
          <el-input v-model="form.price" placeholder="请输入进价" />
        </el-form-item>
        <el-form-item label="售价" prop="vipPrice">
          <el-input v-model="form.vipPrice" placeholder="请输入售价" />
        </el-form-item>
        <el-form-item label="利润" prop="postage">
          <div style="font-weight: 600; font-size: 18px">
            {{
              Number.parseFloat(form.vipPrice) -
                Number.parseFloat(form.price) || "0"
            }}
          </div>
          <!--          <el-input :disabled="true" v-model="form.vipPrice" placeholder="请输入计算利润" />-->
          <!-- <el-input  v-model="form.postage" placeholder="请输入利润" /> -->
        </el-form-item>
        <el-form-item label="赠送倍数" prop="giftAmount">
          <!-- <el-form-item>{{form.quota/form.postage}}</el-form-item> -->
          <el-input v-model="form.giftAmount" placeholder="请输入赠送倍数" />
        </el-form-item>
        <el-form-item label="销量" prop="sales">
          <el-input v-model.number="form.sales" placeholder="请输入销量" />
        </el-form-item>
        <el-form-item label="库存" prop="stock">
          <el-input v-model.number="form.stock" placeholder="请输入库存" />
        </el-form-item>
        <el-form-item label="贡献值" prop="quota">
          <el-input v-model.number="form.quota" placeholder="请输入贡献值" />
        </el-form-item>
        <!-- 品牌 -->
        <el-form-item label="品牌" prop="brandId">
          <el-select
            v-model="form.mainBrandId"
            @change="handleMainChange"
            placeholder="请选择主品牌"
          >
            <el-option
              v-for="item in brandList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>

          <el-select v-model="form.brandId" placeholder="请选择子品牌">
            <el-option
              v-for="item in childBrandList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="排序" prop="sort">
          <el-input v-model.number="form.sort" placeholder="请输入序号" />
        </el-form-item>
        <el-form-item label="是否事业" prop="isBiz">
          <el-switch
            v-model="form.isBiz"
            inactive-text="否"
            :inactive-value="0"
            :active-value="1"
            active-text="是"
          >
          </el-switch>
        </el-form-item>
        <el-form-item label="是否限购" prop="isLimit">
          <el-row>
            <el-col :span="8">
              <el-switch
                v-model="form.isLimit"
                inactive-text="不限"
                active-text="限购"
                :inactive-value="0"
                :active-value="1"
                active-color="#ff4949"
                inactive-color="#13ce66"
              >
              </el-switch>
            </el-col>
            <el-col :span="16" v-show="form.isLimit == 1">
              <div style="width: 20%; display: inline-block">限购数量：</div>
              <el-input
                v-model="form.limitNum"
                placeholder="请输入限购数量"
                oninput="value=value.replace(/[^\d]/g,'')"
                style="width: 80%"
              />
            </el-col>
          </el-row>
        </el-form-item>

        <el-form-item label="混合支付">
          <div>
            <el-switch
              v-model="isMixPay"
              inactive-text="否"
              active-text="是"
              @change="payTypeChanged"
            >
            </el-switch>
          </div>
          <el-row v-show="this.isMixPay" style="margin-top: 1%">
            <el-col :span="8" style="display: flex">
              现金比例：<el-input
                :value="form.cashRatio"
                style="width: 50%"
                :disabled="true"
              />%
            </el-col>
            <el-col :span="8" style="display: flex">
              gtfy比例：<el-input
                v-model="form.passProportion"
                style="width: 50%"
                @input="gtfyInputChanged"
              />%
            </el-col>
            <el-col :span="8" style="display: flex">
              <el-input-number
                v-model="form.passProportion"
                :min="0"
                :max="100"
                width="100"
                @change="gtfyChanged"
              ></el-input-number
              >%
            </el-col>
          </el-row>
        </el-form-item>
        <el-form-item label="实际支付">
          <el-row>
            <el-col :span="2" style="border: 1px solid transparent"></el-col>
            <el-col v-if="form.cashRatio" :span="7">
              <div class="actualPay" style="width: 37%">
                ￥{{ (form.vipPrice * form.cashRatio) / 100 }}
              </div>
            </el-col>
            <el-col v-else :span="7">
              <div class="actualPay" style="width: 37%">
                ￥{{ form.vipPrice }}
              </div>
            </el-col>
            <el-col :span="14">
              gtfy
              <div class="actualPay" style="width: 18%; margin-left: 3%">
                {{ (form.vipPrice * form.passProportion) / 100 }}
              </div>
            </el-col>
          </el-row>
        </el-form-item>
        <!-- <el-form-item label="现金" prop="quota">
          <el-input v-model="form.cashRatio" placeholder="请输入贡献值" />
        </el-form-item> -->
        <el-form-item label="状态">
          <el-radio-group v-model="form.status">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>

        <el-form-item label="source" v-show="false">
          <el-switch
            :disabled="true"
            v-model="form.source"
            active-color="#13ce66"
            inactive-color="#ff4949"
            active-value="2"
            inactive-value="1"
          >
          </el-switch>
        </el-form-item>

        <el-form-item label="规格">
          <SkuChoice
            ref="skuchoice"
            :price="form.price"
            :vipPrice="form.vipPrice"
            :giftAmount="form.giftAmount"
            @submit="handleSubmit"
          ></SkuChoice>
        </el-form-item>

        <!-- 选择sku -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listProduct,
  getProduct,
  delProduct,
  addProduct,
  updateProduct,
  exportProduct,
} from "@/api/ds/product";

import { listCategory } from "@/api/ds/category";
import ImageUpload from "@/components/ImageUpload";
import ImagesUpload from "@/components/ImagesUpload";
import Editor from "@/components/Editor";
import { getToken } from "@/utils/auth";
import SkuChoice from "./components/SkuChoice.vue";

// 引入品牌
import { brandList } from "@/api/ds/brand";

export default {
  name: "Product",
  components: {
    ImageUpload,
    ImagesUpload,
    Editor,
    SkuChoice,
  },
  data() {
    var validateID = (rule, value, callback) => {
      if (value) {
        if (!/^([1-9][0-9]*){1,3}$/.test(value)) {
          callback(new Error("请输入正确的值"));
        } else {
          callback();
        }
      } else {
        callback(new Error("请输入值"));
      }
    };
    var validatePrice = (rule, value, callback) => {
      if (value) {
        if (!/^([1-9][0-9]*)+(.[0-9]{1,2})?$/.test(value)) {
          callback(new Error("请输入正确的价格（最多两位小数）"));
        } else {
          callback();
        }
      } else {
        callback(new Error("请输入价格"));
      }
    };
    return {
      uploadImgUrl: process.env.VUE_APP_BASE_API + "/common/uploadImage", // 上传的图片服务器地址
      headers: {
        Authorization: "Bearer " + getToken(),
      },
      filesList: [],
      categoryList: [], // 分类列表
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 商品信息表格数据
      productList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        source: 1,
        pageNum: 1,
        pageSize: 10,
        image: null,
        tagId: null,
        sliderImage: null,
        name: null,
        info: null,
        keyword: null,
        barCode: null,
        brand: null,
        cateId: null,
        price: null,
        cash: null,
        vipPrice: null,
        postage: null,
        presellTime: null,
        sort: null,
        sales: null,
        stock: null,
        status: null,
        isBenefit: null,
        isBest: null,
        isNew: null,
        isPostage: null,
        isDel: null,
        browse: null,
        origin: null,
        size: null,
        saveWay: null,
        isLimit: null,
        limitNum: null,
        specifications: null,
        realStock: null,
        proDate: null,
        expDate: null,
        shareMsg: null,
        postscript: null,
        remark: null,
        createTime: null,
        quota: null,
        giftAmount: null,
        isBiz: null,
        passProportion: null,
        cashRatio: null,
        shipmentStatus: null,
        storeId: 0,
      },
      // 表单参数
      form: {
        hasSku: false,
        size: null,
        integral: 0,
        greenPoints: null,
      },
      // 表单校验
      rules: {
        image: [{ required: true, message: "商品图不能为空", trigger: "blur" }],
        sliderImage: [
          { required: true, message: "轮播图不能为空", trigger: "blur" },
        ],
        name: [{ required: true, message: "商品名不能为空", trigger: "blur" }],
        cateId: [{ required: true, validator: validateID, trigger: "blur" }],
        price: [{ required: true, message: "进价不能为空", trigger: "blur" }],
        vipPrice: [
          { required: true, message: "售价不能为空", trigger: "blur" },
        ],
        sales: [{ required: true, message: "销量不能为空", trigger: "blur" }],
        stock: [{ required: true, message: "库存不能为空", trigger: "blur" }],
        quota: [{ required: true, message: "贡献值不能为空", trigger: "blur" }],
        giftAmount: [
          { required: true, message: "赠送倍数不能为空", trigger: "blur" },
        ],
        limitNum: [
          { required: true, message: "限购数量不能为空", trigger: "blur" },
        ],
        // vipPrice:[{
        //     required:true,message:"利润不能为空",trigger:'change'},
        //     { min:0,max:1000000,}
        //   ],quota:[{
        //     required:true,message:"贡献值不能为空",trigger:'change'},
        //     { min:0,max:1000000,
        //   }],
        // giftAmount:[{
        //   required:true,message:"赠送倍数不能为空",trigger:'change'},
        //   { min:0,max:1000000,
        // }],
        // isBiz:[{
        //     required:true,message:"是否现金不能为空"},
        //     { min:0,max:1000000,
        //     }],postage:[{
        //     required:true,message:"进价不能为空"},
        //     { min:0,max:1000000,
        //     }],
      },
      isMixPay: false, // 是否混合支付
      categoryOptions: [
        // 分类下拉框
        {
          value: "0-100",
          label: "现金",
        },
        {
          value: "101-200",
          label: "积分",
        },
        {
          value: "201-300",
          label: "事业",
        },
      ],

      brandList: [],
      childBrandList: [],
      allBrandList: [],
    };
  },
  created() {
    this.getList();
    this.getCateList();
    this.getBrandList();
  },
  computed: {},
  watch: {},
  methods: {
    async handleMainChange(value) {
      let res = await brandList({ brandId: value });
      if (res.code === 200) {
        this.childBrandList = res.rows;
      }
    },
    async getBrandList() {
      let res = await brandList({ grade: 1 });
      if (res.code === 200) {
        this.brandList = res.rows;
      }

      let res1 = await brandList();
      if (res1.code === 200) {
        this.allBrandList = res.rows;
      }
    },
    handleSubmit(ids) {
      // 必须使用魔术方法 不然无法设置响应式数据
      this.$set(this.form, "size", ids.join(","));
    },
    /** 查询商品信息列表 */
    getList() {
      this.loading = true;
      listProduct(this.queryParams).then((response) => {
        this.productList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    getCateList() {
      listCategory().then((response) => {
        this.categoryList = response.rows;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.$refs.upload.clearFiles(); // 取消按钮也要清一遍轮播图
      this.reset();
      // 清理dialog form缓存
      this.$refs.skuchoice.hasSubmit = false;
    },
    dialogClosed() {
      this.open = false;
      this.$refs.upload.clearFiles(); // 取消按钮也要清一遍轮播图
      this.reset();
      // 清理dialog form缓存
      this.$refs.skuchoice.hasSubmit = false;
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        image: null,
        tagId: null,
        sliderImage: [],
        name: null,
        info: null,
        keyword: null,
        barCode: null,
        brand: null,
        cateId: null,
        price: null,
        vipPrice: null,
        postage: null,
        presellTime: null,
        sort: null,
        sales: null,
        stock: null,
        status: 0,
        isBenefit: null,
        isBest: null,
        isNew: null,
        isPostage: null, // 是否包邮
        isDel: null,
        browse: null,
        origin: null,
        size: null,
        saveWay: null,
        isLimit: null,
        limitNum: null,
        specifications: null,
        realStock: null,
        proDate: null,
        expDate: null,
        shareMsg: null,
        postscript: null,
        remark: null,
        createTime: null,
        quota: null,
        giftAmount: null,
        isBiz: null,
        passProportion: null,
        cashRatio: 100,
        source: 1,
        hasSku: false,
        size: null,
        storeId: 0,
        integral: 0,
        greenPoints: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },

    // 操作上下架switch按钮
    statusChecked(e, row) {
      row.status = e;
      updateProduct(row).then((response) => {
        this.msgSuccess("修改成功");
        this.getList();
      });
    },
    //--start-- 图片上传的状态出来
    //检测文件变动获取文件
    fileChange(file, fileList) {},

    //检测文件成功、删除 都先把原有清空，再重新赋值。
    fileRemove(file, fileList) {
      this.filesList = [];
      for (let index = 0; index < fileList.length; index++) {
        this.filesList.push(fileList[index].url);
      }
    },
    handleUploadSuccess(response, file, fileList) {
      this.filesList = [];
      for (let index = 0; index < fileList.length; index++) {
        if (fileList[index].response) {
          this.filesList.push(fileList[index].response.url);
        } else {
          this.filesList.push(fileList[index].url);
        }
      }
    },
    //--end--
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.isMixPay = false;
      this.open = true;
      this.title = "添加商品信息";

      // 清空dialog
      this.$refs.skuchoice.initStep();
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getProduct(id).then((response) => {
        this.form = response.data;
        this.isMixPay =
          this.form.passProportion && this.form.passProportion > 0
            ? true
            : false; // 是否混合支付标识
        // start 多图需要转化
        if (this.form) {
          let arr = [];
          let fileList = this.form.sliderImage.split(",");
          for (let i = 0; i < fileList.length; i++) {
            let obj = new Object();
            obj.name = i.toString();
            obj.url = fileList[i];
            arr.push(obj);
          }
          this.filesList = arr;
        }
        // end 多图需要转化
        this.open = true;
        this.title = "修改商品信息";

        // 如果有sizeId,则需要初始化sizeId
        if (this.form.size && this.form.size != "") {
          setTimeout(() => {
            this.$refs.skuchoice.init(this.form.size);
          }, 500);
        }

        this.handleMainChange(this.form.mainBrandId);
      });
    },
    gtfyChanged(value) {
      if (value) {
        this.form.passProportion = value;
        this.form.cashRatio = 100 - Number.parseFloat(value);
      }
    },
    gtfyInputChanged(value) {
      this.form.cashRatio = 100 - value;
    },
    /** 提交按钮 */
    submitForm() {
      if (this.form.cateId == 275) {
        this.form.passProportion = 0;
        this.form.cashRatio = 100;
        this.form.isBiz = 0;
        this.isMixPay = false;
      } else {
        this.form.greenPoints = null;
      }

      /** start 防止用户先点击限购，已经输入数量之后，再次点击不限购，limitNum会存入以前输入的数字。 */
      if (this.form.isLimit == 0) {
        this.form.limitNum = 0;
      }
      if (!this.form.isBiz) {
        this.form.isBiz = 0;
      }
      if (!this.form.storeId) {
        this.form.storeId = 0;
      }
      /** end */

      /**start  this.form.sliderImage Array转成String */
      this.form.sliderImage = [];
      for (let i = 0; i < this.filesList.length; i++) {
        if (this.filesList[i].url) {
          this.form.sliderImage.push(this.filesList[i].url);
        } else {
          this.form.sliderImage.push(this.filesList[i]);
        }
      }
      /**end  this.form.sliderImage Array转成String */

      /**start 做个判断 gtfy比例为0时 现金比例为100 为防止数据库现金比率为null而写*/
      if (this.form.passProportion == 0) this.form.cashRatio = 100;

      if (
        this.form.cateId > 100 &&
        this.form.cateId < 200 &&
        !this.form.integral
      ) {
        this.$notify({
          title: "需要填写积分",
          message: "类目在100-200之间的请填写积分",
          type: "warning",
        });

        return;
      }

      /**end 做个判断 gtfy比例为0时 现金比例为100 为防止数据库现金比率为null而写*/
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (
            (this.form.price && this.form.vipPrice) ||
            this.form.vipPrice === 0 ||
            this.form.price === 0
          ) {
            this.form.postage =
              Number.parseFloat(this.form.vipPrice) -
              Number.parseFloat(this.form.price);
          }
          this.form.sliderImage = this.form.sliderImage.toString();
          if (this.form.id != null) {
            updateProduct(this.form).then((response) => {
              this.msgSuccess("修改成功");
              this.$refs.upload.clearFiles();
              this.open = false;
              this.getList();
            });
          } else {
            addProduct(this.form).then((response) => {
              this.msgSuccess("新增成功");
              this.$refs.upload.clearFiles();
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm(
        '是否确认删除商品信息编号为"' + ids + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return delProduct(ids);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有商品信息数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return exportProduct(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
        });
    },
    /** 当关闭混合支付按钮时，gtfy支付比例归0 */
    payTypeChanged() {
      if (!this.isMixPay) {
        this.form.passProportion = 0;
        this.form.cashRatio = 100;
      }
    },
  },
};
</script>
<style>
.actualPay {
  width: 33%;
  text-align: center;
  margin-left: 6%;
  display: inline-block;
  color: white;
  background: #1890ff;
  font-weight: 600;
  border-radius: 4px;
}
</style>
